package cn.shequren.communityPeople.home.presenter;


import com.jz.community.basecomm.mvp.BaseLifeCyclePresent;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.moduleshoppingguide.home.bean.HomeFindBean;
import com.jz.community.moduleshoppingguide.home.model.ShoppingGuideModel;
import com.jz.community.moduleshoppingguide.home.model.ShoppingModelGuideImpl;

import cn.shequren.communityPeople.home.bean.VersionBean;
import cn.shequren.communityPeople.home.model.MainModel;
import cn.shequren.communityPeople.home.model.MainModelImpl;
import cn.shequren.communityPeople.home.ui.MainView;

/**
 * Created by Admin on 2018/3/26 0026.
 */

public class MainPresenter extends BaseLifeCyclePresent<MainView.View> implements MainView.Presenter {


    private MainView.View mView;
    private ShoppingGuideModel shoppingModel;
    private MainModel mainModel;


    public MainPresenter(MainView.View mView) {
        this.mView = mView;
        shoppingModel = new ShoppingModelGuideImpl(mView.getContext());
        mainModel = new MainModelImpl(mView.getContext());
    }


    @Override
    public void getChunnelHomePage(int page, int size, String cityCode) {
        shoppingModel.getChunnelHomePage(page, size, cityCode, new OnLoadListener<HomeFindBean>() {
            @Override
            public void onSuccess(HomeFindBean homeFindBean) {
                mView.showHomeChannel(homeFindBean);
            }

            @Override
            public void onFail(String s, int code) {
                mView.showError(s, 0);
            }
        });
    }

    @Override
    public void updateVersion(String versionName) {
        mainModel.updateVersion(versionName, new OnLoadListener<VersionBean>() {
            @Override
            public void onSuccess(VersionBean versionBean) {
                mView.setUpdateData(versionBean);
            }

            @Override
            public void onFail(String msg, int code) {
                if (code != 204 && code != 303) {
                    mView.showError(msg, 1);
                }
            }
        });

    }


}
